package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.AreaClient;
import com.salt.admin.api.model.Area;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description 区域（后台管理中心）远程调用失败处理类
 * @Author salt
 * @Date 2020/8/18 16:00
 * @Version 1.0
 */
@Slf4j
@Component
public class AreaClientHystrix implements FallbackFactory<AreaClient> {

    @Override
    public AreaClient create(Throwable throwable) {

        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);

        return new AreaClient() {

            @Override
            public Area get(String id) {
                log.info("--根据ID查询区域异常, id: " + id);
                return null;
            }

            @Override
            public Area getByAreaName(String name) {
                log.info("--根据名称查询区域异常, name: " + name);
                return null;
            }
        };
    }
}
